package com.swing.demo;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

public class SwingTextfield{
	public static void main(String[] args) {
		SwingTextfield sTextfield = new SwingTextfield();
		sTextfield.initFrame();
		
	}
	
    public void initFrame() {
    	JFrame frame = new JFrame("This is a frame");
    	Container container = frame.getContentPane();
    	frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    	JTextField jTextField= new JTextField("demo");
        JTextField textField = new JTextField(16);
        JTextArea jTextArea1=new JTextArea("textarea");

        JComboBox selectBox = new JComboBox<>();
        selectBox.addItem("test001");
        selectBox.addItem("test002");
        selectBox.addItem("test003");
       

        JButton btn = new JButton("提交");
        jTextArea1.addFocusListener(new FocusListener() {
			
			@Override
			public void focusLost(FocusEvent e) {
				// TODO Auto-generated method stub
				System.out.println("leave");
				
			}
			
			@Override
			public void focusGained(FocusEvent e) {
				// TODO Auto-generated method stub
				System.out.println("comming");
				
			}
		});

        btn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.out.println("==== out put====");
				String txt1 = jTextField.getText();
				jTextField.setText("test3333");
				
			}
		});
        
    	container.setLayout(new FlowLayout());
    	container.add(jTextField);
    	container.add(jTextArea1);
    	container.add(textField);
    	container.add(selectBox);
    	container.add(btn);
    	frame.setBounds(100,100,400,400);   

    	frame.setVisible(true);
		
	}
}
